package com.demo.okhttp

import okhttp3.Interceptor
import okhttp3.Response

class LoggingInterceptor : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()

        val t1 = System.nanoTime()
        System.out.println("Sending request ${request.url} on ${chain.connection()}${request.headers}")

        val response = chain.proceed(request)

        val t2 = System.nanoTime()
        System.out.println("Received response for ${request.url}${(t2 - t1) / 1e6}${response.headers}")

        return response
    }
}